package com.ruoyi.system.controller;

import java.util.List;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TicketMovieBaseInfo;
import com.ruoyi.system.service.ITicketMovieBaseInfoService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 电影基本信息Controller
 * 
 * @author ruoyi
 * @date 2022-01-10
 */
@Controller
@RequestMapping("/system/ticketmoviebaseinfo")
public class TicketMovieBaseInfoController extends BaseController
{
    private String prefix = "system/ticketmoviebaseinfo";

    @Autowired
    private ITicketMovieBaseInfoService ticketMovieBaseInfoService;

    @RequiresPermissions("system:ticketmoviebaseinfo:view")
    @GetMapping()
    public String ticketmoviebaseinfo()
    {
        return prefix + "/ticketmoviebaseinfo";
    }

    /**
     * 查询电影基本信息列表
     */
    @RequiresPermissions("system:ticketmoviebaseinfo:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TicketMovieBaseInfo ticketMovieBaseInfo)
    {
        startPage();
        List<TicketMovieBaseInfo> list = ticketMovieBaseInfoService.selectTicketMovieBaseInfoList(ticketMovieBaseInfo);
        return getDataTable(list);
    }

    /**
     * 导出电影基本信息列表
     */
    @RequiresPermissions("system:ticketmoviebaseinfo:export")
    @Log(title = "电影基本信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TicketMovieBaseInfo ticketMovieBaseInfo)
    {
        List<TicketMovieBaseInfo> list = ticketMovieBaseInfoService.selectTicketMovieBaseInfoList(ticketMovieBaseInfo);
        ExcelUtil<TicketMovieBaseInfo> util = new ExcelUtil<TicketMovieBaseInfo>(TicketMovieBaseInfo.class);
        return util.exportExcel(list, "电影基本信息数据");
    }

    /**
     * 新增电影基本信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存电影基本信息
     */
    @RequiresPermissions("system:ticketmoviebaseinfo:add")
    @Log(title = "电影基本信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TicketMovieBaseInfo ticketMovieBaseInfo)
    {
        logger.debug("收到添加电影="+ticketMovieBaseInfo.getImage()+",info="+ticketMovieBaseInfo);
        ticketMovieBaseInfo.setOperateId(ShiroUtils.getUserId());
        ticketMovieBaseInfo.setOperateName(ShiroUtils.getLoginName());
        return toAjax(ticketMovieBaseInfoService.insertTicketMovieBaseInfo(ticketMovieBaseInfo));
    }

    /**
     * 修改电影基本信息
     */
    @RequiresPermissions("system:ticketmoviebaseinfo:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TicketMovieBaseInfo ticketMovieBaseInfo = ticketMovieBaseInfoService.selectTicketMovieBaseInfoById(id);
        mmap.put("ticketMovieBaseInfo", ticketMovieBaseInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存电影基本信息
     */
    @RequiresPermissions("system:ticketmoviebaseinfo:edit")
    @Log(title = "电影基本信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TicketMovieBaseInfo ticketMovieBaseInfo)
    {
        ticketMovieBaseInfo.setOperateId(ShiroUtils.getUserId());
        ticketMovieBaseInfo.setOperateName(ShiroUtils.getLoginName());
        return toAjax(ticketMovieBaseInfoService.updateTicketMovieBaseInfo(ticketMovieBaseInfo));
    }

    /**
     * 删除电影基本信息
     */
    @RequiresPermissions("system:ticketmoviebaseinfo:remove")
    @Log(title = "电影基本信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(ticketMovieBaseInfoService.deleteTicketMovieBaseInfoByIds(ids));
    }

    //获取电影信息列表
    @RequiresPermissions("system:ticketmoviebaseinfo:list")
    @GetMapping("/getMovieInfoList")
    @ResponseBody
    public AjaxResult getMovieInfoList(TicketMovieBaseInfo ticketMovieBaseInfo)
    {
        List<TicketMovieBaseInfo> list = ticketMovieBaseInfoService.selectTicketMovieBaseInfoList(ticketMovieBaseInfo);
        AjaxResult result = new AjaxResult();
        result.put("array", list);
        return result;
    }

    //首页的数据统计
//    @RequiresPermissions("system:ticketmoviebaseinfo:list")
    @GetMapping("/getAccountingData")
    @ResponseBody
    public AjaxResult getAccountingData()
    {
//        List<TicketMovieBaseInfo> list = ticketMovieBaseInfoService.selectTicketMovieBaseInfoList(ticketMovieBaseInfo);
        AjaxResult result = new AjaxResult();
//        result.put("array", list);
        return result;
    }
}
